package vn.orderonline.com.core.business.toorder;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import vn.orderonline.com.core.business.dto.DrinkBasketDto;
import vn.orderonline.core.dao.entity.DrinkBasket;
import vn.orderonline.core.dao.toorder.DrinkBasketDao;

@Service
@Transactional
public class DrinkBasketImpl implements IDrinkBasket {
	
	@Autowired
	private DrinkBasketDao drinkBasketDao;

	@Override
	public List<DrinkBasketDto> getAllByOrderId(Integer orderId) {
		List<DrinkBasket> list = drinkBasketDao.findByProp("id.orderId", orderId);
		List<DrinkBasketDto> listDto = null;
		if (!list.isEmpty()) {
			listDto = new ArrayList<>();
			DrinkBasketDto dto = null;
			for (DrinkBasket db : list) {
				dto = new DrinkBasketDto();
				dto.setDrinkId(db.getId().getDrinkId());
				dto.setOrderId(db.getId().getOrderId());
				dto.setAmount(db.getAmount());
				dto.setDrinkName(db.getDrinkName());
				dto.setPrice(db.getPrice());
				listDto.add(dto);
			}
		}
		return listDto;
	}

	
	
}
